Completed
Push — master ( 024748...e197a7 )
by Yannick
34:20
created

map.common.js ➔ unitaltitude   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
function getCookie(cname) {
2
    var name = cname + "=";
3
    var ca = document.cookie.split(';');
4
    for(var i=0; i<ca.length; i++) {
5
	var c = ca[i];
6
	while (c.charAt(0)==' ') c = c.substring(1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7
	if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
    }
9
    return "";
10
}
11
12
function delCookie(cname) {
13
    document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
14
}
15
16
function createCookie(name, value, days) {
17
    var date, expires;
18
    if (days) {
19
	date = new Date();
20
	date.setTime(date.getTime()+(days*24*60*60*1000));
21
	expires = "; expires="+date.toGMTString();
22
    } else {
23
	expires = "";
24
    }
25
    document.cookie = name+"="+value+expires+"; path=/";
26
}
27
28
function mapType(selectObj) {
29
    var idx = selectObj.selectedIndex;
30
    var atype = selectObj.options[idx].value;
31
    var type = atype.split('-');
32
    if (type[0] == 'Mapbox') {
33
	createCookie('MapType',type[0],9999);
34
	createCookie('MapTypeId',type[1],9999);
35
	if (getCookie('Map2D3DSync')) {
36
	    createCookie('MapType3D',type[0],9999);
37
	    createCookie('MapType3DId',type[1],9999);
38
	}
39
    } else {
40
	createCookie('MapType',atype,9999);
41
	if (getCookie('Map2D3DSync')) {
42
	    createCookie('MapType3D',atype,9999);
43
	}
44
    }
45
    window.location.reload();
46
}
47
function mapType3D(selectObj) {
48
    var idx = selectObj.selectedIndex;
49
    var atype = selectObj.options[idx].value;
50
    var type = atype.split('-');
51
    if (type[0] == 'Mapbox') {
52
	createCookie('MapType3D',type[0],9999);
53
	createCookie('MapType3DId',type[1],9999);
54
	if (getCookie('Map2D3DSync')) {
55
	    createCookie('MapType',type[0],9999);
56
	    createCookie('MapTypeId',type[1],9999);
57
	}
58
    } else {
59
	createCookie('MapType3D',atype,9999);
60
	if (getCookie('Map2D3DSync')) {
61
	    createCookie('MapType',atype,9999);
62
	}
63
    }
64
    window.location.reload();
65
}
66
function clickSyncMap2D3D(cb) {
67
    createCookie('Map2D3DSync',cb.checked,9999);
68
    if (cb.checked) {
69
	createCookie('MapType3D',getCookie('MapType'),9999);
70
	createCookie('MapType3DId',getCookie('MapTypeId'),9999);
71
    }
72
}
73
74
function terrainType(selectObj) {
75
    var idx = selectObj.selectedIndex;
76
    var atype = selectObj.options[idx].value;
77
    var type = atype.split('-');
78
    document.cookie =  'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
79
    createCookie('MapTerrain',type,9999);
80
    window.location.reload();
81
}
82
83
function sattypes(selectObj) {
84
    var sattypes = [], sattype;
85
    for (var i=0, len=selectObj.options.length; i< len;i++) {
86
	sattype = selectObj.options[i];
87
	if (sattype.selected) {
88
	    sattypes.push(sattype.value);
89
	}
90
    }
91
    createCookie('sattypes',sattypes.join(),2);
92
    updateSat();
93
}
94
function airlines(selectObj) {
95
    var airs = [], air;
96
    for (var i=0, len=selectObj.options.length; i< len;i++) {
97
	air = selectObj.options[i];
98
	if (air.selected) {
99
	    airs.push(air.value);
100
	}
101
    }
102
    createCookie('filter_Airlines',airs.join(),2);
103
}
104
function airlinestype(selectObj) {
105
    var idx = selectObj.selectedIndex;
106
    var airtype = selectObj.options[idx].value;
107
    createCookie('filter_airlinestype',airtype,2);
108
}
109
function alliance(selectObj) {
110
    var idx = selectObj.selectedIndex;
111
    var alliance = selectObj.options[idx].value;
112
    createCookie('filter_alliance',alliance,2);
113
}
114
function identfilter() {
115
    var ident = $("#identfilter").value;
116
    createCookie('filter_ident',ident,2);
117
}
118
function mmsifilter() {
119
    var ident = $("#mmsifilter").value;
120
    createCookie('filter_mmsi',ident,2);
121
}
122
function removefilters() {
123
    // Get an array of all cookie names (the regex matches what we don't want)
124
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
125
    // Remove any that match the pattern
126
    for (var i = 0; i < cookieNames.length; i++) {
127
	if (/^filter_/.test(cookieNames[i])) {
128
	    delCookie(cookieNames[i]);
129
	}
130
    }
131
    window.location.reload();
132
}
133
function sources(selectObj) {
134
    var sources = [], source;
135
    for (var i=0, len=selectObj.options.length; i< len;i++) {
136
	source = selectObj.options[i];
137
	if (source.selected) {
138
	    sources.push(source.value);
139
	}
140
    }
141
    createCookie('filter_Sources',sources.join(),2);
142
}
143
144
145
function show2D() {
146
    createCookie('MapFormat','2d',10);
147
    if (document.getElementById("pointtype").className == 'tracker') {
148
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
149
    } else if (document.getElementById("pointtype").className == 'marine') {
150
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
151
    } else {
152
	createCookie('MapTrack',document.getElementById("pointident").className,1);
153
    }
154
    window.location.reload();
155
}
156
function show3D() {
157
    createCookie('MapFormat','3d',10);
158
    if (document.getElementById("pointtype").className == 'tracker') {
159
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
160
    } else if (document.getElementById("pointtype").className == 'marine') {
161
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
162
    } else {
163
	createCookie('MapTrack',document.getElementById("pointident").className,1);
164
    }
165
    window.location.reload();
166
}
167
function clickPolar(cb) {
168
    createCookie('polar',cb.checked,9999);
169
    window.location.reload();
170
}
171
function clickDisplayAirports(cb) {
172
    createCookie('displayairports',cb.checked,9999);
173
    window.location.reload();
174
}
175
function clickDisplayISS(cb) {
176
    createCookie('displayiss',cb.checked,9999);
177
    updateSat();
178
}
179
function clickDisplayMinimap(cb) {
180
    createCookie('displayminimap',cb.checked,9999);
181
    window.location.reload();
182
}
183
function clickShadows(cb) {
184
    createCookie('map3dnoshadows',cb.checked,9999);
185
    window.location.reload();
186
}
187
function clickSingleModel(cb) {
188
    createCookie('singlemodel',cb.checked,9999);
189
}
190
function clickUpdateRealtime(cb) {
191
    createCookie('updaterealtime',cb.checked,9999);
192
}
193
function clickVATSIM(cb) {
194
    createCookie('filter_ShowVATSIM',cb.checked,2);
195
}
196
function clickIVAO(cb) {
197
     createCookie('filter_ShowIVAO',cb.checked,2);
198
}
199
function clickphpVMS(cb) {
200
    createCookie('filter_ShowVMS',cb.checked,2);
201
}
202
function clickSBS1(cb) {
203
    createCookie('filter_ShowSBS1',cb.checked,2);
204
}
205
function clickAPRS(cb) {
206
    createCookie('filter_ShowAPRS',cb.checked,2);
207
}
208
function clickDisplayGroundStation(cb) {
209
    createCookie('show_GroundStation',cb.checked,2);
210
    window.location.reload();
211
}
212
function clickDisplayWeatherStation(cb) {
213
    createCookie('show_WeatherStation',cb.checked,2);
214
    window.location.reload();
215
}
216
function clickDisplayWeather(cb) {
217
    createCookie('show_Weather',cb.checked,2);
218
//    window.location.reload();
219
}
220
function clickDisplayLightning(cb) {
221
    createCookie('show_Lightning',cb.checked,2);
222
    window.location.reload();
223
}
224
function clickDisplayFires(cb) {
225
    createCookie('show_Fires',cb.checked,2);
226
    window.location.reload();
227
}
228
function clickDisplay2DBuildings(cb) {
229
    createCookie('Map2DBuildings',cb.checked,2);
230
    window.location.reload();
231
}
232
function unitdistance(selectObj) {
233
    var idx = selectObj.selectedIndex;
234
    var unit = selectObj.options[idx].value;
235
    createCookie('unitdistance',unit,9999);
236
}
237
function unitspeed(selectObj) {
238
    var idx = selectObj.selectedIndex;
239
    var unit = selectObj.options[idx].value;
240
    createCookie('unitspeed',unit,9999);
241
}
242
function unitaltitude(selectObj) {
243
    var idx = selectObj.selectedIndex;
244
    var unit = selectObj.options[idx].value;
245
    createCookie('unitaltitude',unit,9999);
246
}
247
function addarchive(begindate,enddate) {
248
    console.log('Add archive');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
249
    createCookie('archive',true,2);
250
    createCookie('archive_begin',begindate,2);
251
    createCookie('archive_end',enddate,2);
252
    createCookie('archive_speed',document.getElementById("archivespeed").value,2);
253
    window.location.reload();
254
}
255
function noarchive() {
256
    console.log('Exit archive!');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
257
    delCookie('archive');
258
    delCookie('archive_begin');
259
    delCookie('archive_end');
260
    delCookie('archive_speed');
261
    window.location.reload();
262
}
263
function msgbox(text,buttontext) {
264
	buttontext = buttontext || "OK";
265
	$("<div>" + text + "</div>").dialog({
266
	    dialogClass: "no-close",
267
	    buttons: [{
268
		text: buttontext,
269
		click: function() {
270
		    $( this ).dialog( "close" );
271
		    $(this).remove();
272
		}
273
	    }]
274
	});
275
}
276
function generateRandomPoint (latitude,longitude,height,diff,radius) {
277
278
	//console.log('height: '+height+' - diff: '+diff);
279
	radius = Math.random()*radius;
280
	latitude = latitude*(Math.PI/180.0);
281
	longitude = longitude*(Math.PI/180.0);
282
	
283
	const sinLat = 	Math.sin(latitude)
284
	const cosLat = 	Math.cos(latitude)
285
286
	/* go fixed distance in random direction*/
287
	const bearing = Math.random() * Math.PI*2
288
	const theta = radius/6371000
289
	const sinBearing = Math.sin(bearing)
290
	const cosBearing = Math.cos(bearing)
291
	const sinTheta = Math.sin(theta)
292
	const cosTheta = Math.cos(theta)
293
    
294
	latitude = Math.asin(sinLat*cosTheta+cosLat*sinTheta*cosBearing);
295
	longitude = longitude + Math.atan2( sinBearing*sinTheta*cosLat, cosTheta-sinLat*Math.sin(latitude ));
296
	/* normalize -PI -> +PI radians */
297
	longitude = ((longitude+(Math.PI*3))%(Math.PI*2))-Math.PI
298
	var h = height+(Math.random()*diff)
299
	//console.log('h: '+h);
300
	return {
301
	    latitude: latitude/(Math.PI/180.0),
302
	    longitude: longitude/(Math.PI/180.0),
303
	    height: h
304
	};
305
306
}